package com.koo.modules.b2b.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.b2b.dao.B2bStoreDao;
import com.koo.modules.b2b.entity.B2bStoreEntity;
import com.koo.modules.b2b.service.B2bStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class B2bStoreServiceImpl extends ServiceImpl<B2bStoreDao, B2bStoreEntity> implements B2bStoreService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<B2bStoreEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), B2bStoreEntity::getStoreName, key)
                .or().eq(MyStrUtil.isNotEmpty(key), B2bStoreEntity::getStoreCode, key);

        IPage<B2bStoreEntity> page = this.page(
                new Query<B2bStoreEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<B2bStoreEntity> listStoreByPrefixAndTransportDate(String prefix, Timestamp maxTransportDate) {
        return baseMapper.listStoreByPrefixAndTransportDate(prefix, maxTransportDate);
    }
}